var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#login',                                                                   
    //vue实例 的data属性
    data:function(){
        return{
        	loginLoading:false,
        	lablePosition:'left',
        	loginForm:{},
        	loginRules: {
              //validator：校验器(其实就是上面自定义的方法) trigger:触发事件
        	  userCode: [ { required: true, message: '请填写用户名', trigger: 'change,blur' }],
        	  type: [ { required: true, message: '请选择身份', trigger: 'change,blur' }],
              password:[{ required: true, message: '请填写密码', trigger: 'change,blur' }]
            }
        };
    },
    //vue实例 的methods
    methods:{
        submit:function(formName){
        	
        	vm.$refs[formName].validate(function(valid) {
        		
                if (valid) {
                	vm.loginLoading = true;
                	var url = './login.action';
                	var user = {
                		"user.userCode":vm.loginForm.userCode,
                		"user.password":vm.loginForm.password,
                		"user.type":vm.loginForm.type
                	};
                	
                	pb.ajaxPost(url,user,function(r){
                		if(r.code == 0){
                			vm.loginLoading = false;
                			window.location.href="index.jsp"; 
                		}else if(r.code == 1){
                			vm.loginLoading = false;
                			window.location.href="indexAdmin.jsp"; 
                		}else if(r.code == -1){
                			vm.loginLoading = false;
                			pb.alertErr("您没有该权限");
                		}
                		else{
                			vm.loginLoading = false;
                			pb.alertErr("用户名或密码错误");
                		}
                	},function(err){
                		pb.alertErr("登录超时");
                		vm.loginLoading = false;
                	});
                }
        	});
        },
        /*重置表单项*/
        resetForm:function(formName){
          vm.$refs[formName].resetFields();
        },
        regist:function(){
        	//window.location.href="register.html";
        	window.open("register.html","_blank");  
        }
        
    }
    //vue实例 的methods结束
});
$(document).ready(function(e) {
	$(this).keydown(function (e){
		if(e.which == "13"){
			vm.submit('refForm');//触发该事件
		} 
	});
});